package com.thwj.project.app.event;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.thwj.project.biz.domain.UserMessage;
import com.thwj.project.biz.service.IUserMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.Date;

@Slf4j
@Component
public class MessageEventConsumer {

    @Autowired
    IUserMessageService userMessageService;

    @Async
    @EventListener
    public void  onUserMessageReadEvent(UserMessageReadEvent event) {
        // 标记消息为已读
        userMessageService.update(new UpdateWrapper<UserMessage>()
                .set("has_read", true)
                .set("read_date", new Date())
                .in("id", event.getMessageIdList()));
    }
}
